package ${packageName}.controller;

import ${packageName}.entity.${tableInfo.className};
import ${packageName}.service.${tableInfo.className}Service;
import com.sssre.lttcloud.common.result.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * ${tableInfo.tableComment}控制器
 * 
 * @author ${tableInfo.author}
 * @date ${.now?string("yyyy-MM-dd")}
 */
@RestController
@RequestMapping("/${tableInfo.className?uncap_first}")
@CrossOrigin
public class ${tableInfo.className}Controller {

    @Autowired
    private ${tableInfo.className}Service ${tableInfo.className?uncap_first}Service;

    /**
     * 保存${tableInfo.tableComment}
     */
    @PostMapping
    public Result<${tableInfo.className}> save${tableInfo.className}(@Valid @RequestBody ${tableInfo.className} ${tableInfo.className?uncap_first}) {
        return ${tableInfo.className?uncap_first}Service.save${tableInfo.className}(${tableInfo.className?uncap_first});
    }

    /**
     * 根据ID查询${tableInfo.tableComment}
     */
    @GetMapping("/{id}")
    public Result<${tableInfo.className}> get${tableInfo.className}ById(@PathVariable Long id) {
        return ${tableInfo.className?uncap_first}Service.get${tableInfo.className}ById(id);
    }

    /**
     * 查询所有${tableInfo.tableComment}
     */
    @GetMapping("/list")
    public Result<List<${tableInfo.className}>> getAll${tableInfo.className}s() {
        return ${tableInfo.className?uncap_first}Service.getAll${tableInfo.className}s();
    }

    /**
     * 分页查询${tableInfo.tableComment}
     */
    @GetMapping("/page")
    public Result<IPage<${tableInfo.className}>> get${tableInfo.className}Page(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        Page<${tableInfo.className}> page = new Page<>(pageNum, pageSize);
        return ${tableInfo.className?uncap_first}Service.get${tableInfo.className}Page(page);
    }

    /**
     * 根据ID删除${tableInfo.tableComment}
     */
    @DeleteMapping("/{id}")
    public Result<String> delete${tableInfo.className}ById(@PathVariable Long id) {
        return ${tableInfo.className?uncap_first}Service.delete${tableInfo.className}ById(id);
    }

    /**
     * 批量删除${tableInfo.tableComment}
     */
    @DeleteMapping("/batch")
    public Result<String> delete${tableInfo.className}Batch(@RequestBody List<Long> ids) {
        return ${tableInfo.className?uncap_first}Service.delete${tableInfo.className}Batch(ids);
    }
} 